<!DOCTYPE html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- jquery -->
    <script src="../../frame/semanticUI/jquery.min.js"></script>
    <!-- CDN引入semanticUI框架 -->
    <link rel="stylesheet" type="text/css" href="../../frame/semanticUI/UI-master/semantic.min.css">
    <!-- semanticUI依赖于Jquery -->
    <script src="../../frame/semanticUI/UI-master/semantic.min.js"></script>
    <!-- markDown插件 -->
    <link rel="stylesheet" href="../../plugin/editormd/css/editormd.min.css">


    <link rel="stylesheet" href="../../frame/elementUI/lib-master/theme-chalk/index.css"/>
    <!-- 必须先引入vue，  后使用element-ui -->
    <script src="../../frame/elementUI/vue.js"></script>
    <!-- 引入element 的组件库-->
    <script src="../../frame/elementUI/lib-master/index.js"></script>

    <link rel="stylesheet" href="../../css/back.css">
    <title>后台发布页</title>

</head>


<script>
    $(function () {
        //表单验证
        $('.ui.form').form({
            fields:{
                title:{
                    identifier: 'title',
                    rules:[
                        {type:'empty',prompt: '标题: 请输入博客标题'},
                        {type:'maxLength[50]',prompt:'最大长度不能超过45'}
                    ]
                },
                content:{
                    identifier: 'content',
                    rules:[
                        {type:'empty',prompt: '内容: 请输入内容'},
                    ]
                },
                firstPicture:{
                    identifier: 'firstPicture',
                    rules:[
                        {type:'empty',prompt: '图片: 请输入图片地址'},
                    ]
                },
                typeId:{
                    identifier: 'typeId',
                    rules:[
                        {type:'empty',prompt: '分类: 请输入分类名称'},
                    ]
                },
            }
        });
        //下拉菜单
        $(".ui.dropdown").dropdown({
            allowAdditions: true //允许添加新的菜单项
        });
        //隐藏域的提交和保存,提交表单
        $('#save-btn').click(function () {
            $('[name="published"]').val(false);
            $('#blog-form').submit();
        });
        $('#publish-btn').click(function () {
            $('[name="published"]').val(true);
            $('#blog-form').submit();
        });
        //分类和标签下拉菜单展示
        axios({
            method: "GET",
            url: "/blog/gainUpdateTypeTag",
        }).then((res)=>{
            console.log(res.data);
            for(type of res.data.typeList){
                $('#menuDiv1').append("<div class="+"item"+" data-value="+type.id+">"+type.name+"</div>")
            }
            for(tag of res.data.tagList){
                for(tag of res.data.upDateTagList){
                    $('#menuDiv2').append("<div class="+"item"+" data-value="+tag.id+">"+tag.name+"</div>")
                }
            }
        });

        //markDown插件初始化
        var contentEditor;
        contentEditor = editormd("md-content", {   //<div id="md-content">
            width   : "100%",
            height  : 640,
            syncScrolling : "single",
            path    : "../../plugin/editormd/lib/"   //指定插件lib路径
        });
    });
</script>
<body>
<div id="app">
    <!-- 导航 -->
    <nav class="ui inverted attached segment" style="padding-top: 5px;height: 70px;padding-left: 100px">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item">管理后台</h2>
            <a href="../host/manage.html"  class="m-item active item" ><i class="home icon"></i>博客</a>
            <a href="../type/types.html"  class="m-item item"><i class="idea icon"></i>分类</a>
            <a href="../record/archives.html"  class="m-item item" ><i class="clone icon"></i>归档</a>
            <a href="../tag/tags.html"  class="m-item item"><i class="tags icon"></i>标签</a>

            <div class="ui right floated dropdown item">
                <div class="text">
                    <img v-bind:src="admin.imgAvatar" class="ui avatar image">
                    <strong >{{admin.username}}</strong>
                </div>
                <i class="ui dropdown icon"></i>
                <div class="menu">
                    <a href="#" class="item">个人中心</a>
                    <a href="/user/logout" class="item">注销</a>
                </div>
            </div>
        </div>
    </nav>
    <!-- 二级菜单 -->
    <div class="ui attached pointing menu">
        <div class="ui container">
            <div class="right menu">
                <a href="push.html" class="active item">发布</a>
                <a href="manage.html" class="item ">列表</a>
            </div>
        </div>
    </div>
    <!-- 中间内容 -->
    <div style="padding-top: 40px;">
        <div class="ui container" style="width: 1000px">
            <form id="blog-form" class="ui form" action="/blog/insert" method="post">
                <!-- 发布是否隐藏域 -->
                <input type="hidden" name="id" :value="rowBlog.id">
                <input type="hidden" name="published">
                <!-- 标题 -->
                <div class="required field">
                    <div class="ui left labeled input">
                        <div class="ui selection compact teal basic dropdown label">
                            <input type="hidden" value="原创">
                            <i class="dropdown icon"></i>
                            <div class="default text">原创</div>
                            <div class="menu">
                                <div class="item" data-value="原创">原创</div>
                                <div class="item" data-value="转载">转载</div>
                                <div class="item" data-value="翻译">翻译</div>
                            </div>
                        </div>
                        <input type="text" name="title" placeholder="标题" :value="rowBlog.title">
                    </div>
                </div>
                <!-- 内容 -->
                <div class="required field">
                    <!-- markDown插件集成 -->
                    <div id="md-content">
                        <textarea type="text" name="content" placeholder="博客内容" style="display: none" :value="rowBlog.content">
                        </textarea>
                    </div>
                </div>
                <!-- 分类和标签 -->
                <div class="two fields">
                    <div class="required field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">分类</label>
                            <div class="ui fluid selection dropdown">
                                <input type="hidden" name="type.id">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu" id="menuDiv1">

                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">标签</label>
                            <div class="ui fluid multiple selection search dropdown">
                                <input type="hidden" name="tagIds">
                                <i class="dropdown icon"></i>
                                <div class="default text">标签</div>
                                <div class="menu" id="menuDiv2">

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 图片地址 -->
                <div class="required field">
                    <div class="ui left labeled input">
                        <label class="ui teal basic label">首图</label>
                        <input type="text" name="firstPicture" placeholder="首图引用地址" :value="rowBlog.firstPicture">
                    </div>
                </div>
                <!-- 单选框组 -->
                <div class="inline fields">
                    <!-- 单选框组 -->
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="checkbox1" name="recommend" class="hidden">
                            <label for="checkbox1"  style="color: #00a8c6"><b>推荐</b></label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="checkbox2" name="shareStatement" class="hidden">
                            <label for="checkbox2" style="color: #00a8c6"><b>转载</b></label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="checkbox3" name="appreciation" class="hidden">
                            <label for="checkbox3" style="color: #00a8c6"><b>赞赏</b></label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="checkbox4" name="commentabled" class="hidden">
                            <label for="checkbox4" style="color: #00a8c6"><b>评论</b></label>
                        </div>
                    </div>
                </div>
                <!--表单验证的错误信息展示-->
                <div class="ui error message"></div>
                <!-- 按钮组 -->
                <div class="ui right aligned container">
                    <button type="button" class="ui button" @click="getBack()">返回</button>
                    <button type="button" id="save-btn" class="ui secondary button">保存</button>
                    <button type="button" id="publish-btn" class="ui teal button" >提交修改</button>
                </div>
            </form>
        </div>
    </div>
    <!-- 页脚 -->
    <footer class="ui inverted vertical segment" style="padding-top: 50px;margin-top: 100px">
        <div class="ui center aligned container">
            <div class="ui inverted divided stackable grid">
                <div class="three wide column">
                    <div class="item">
                        <img src="../../image/mybibi.jpg" class="ui rounded image" style="width: 120px">
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header" style="opacity: 0.8">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="#"class="item">用户故事（User Story）</a>
                        <a href="#"class="item">来自未来的你</a>
                        <a href="#"class="item">fate/zero</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header" style="opacity: 0.8">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="#"class="item">转生成为魔剑那件事</a>
                        <a href="#"class="item">人生初体验</a>
                        <a href="#"class="item">学生故事（Student Story）</a>
                    </div>
                </div>
                <div class="seven wide column" style="opacity: 0.8">
                    <h4 class="ui inverted header">最新博客</h4>
                    <p>鄙人个人博客，仅有于非商业用途，为人民服务是我的职责（分享，程序，开发），来自一只可爱的程序猿</p>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p style="letter-spacing: 2px;opacity: 0.8" >Copyright # 2022-2023 Lirenmi Designed by Lirenmi</p>
            <div class="" style="height: 50px"></div>
        </div>
    </footer>
</div>

</body>
    <!-- axios -->
    <script src="../../frame/axios/axios.min.js"></script>
    <!-- markDown插件 -->
    <script src="../../plugin/editormd/js/editormd.min.js"></script>
<script>

    Vue.config.productionTip=false  //以阻止 vue 在启动时生成生产提示。 <!-- 全局配置 -->
    new Vue({
        el:'#app',
        data:{
            admin:{
                username: '',
                imgAvatar: ''
            },
            rowBlog:{
                id: null,
                title: '',
                context: '',
                typeId: null,
                tagIds: '',
                firstPicture: '',
                recommend: false,
                shareStatement: false,
                appreciation: false,
                commentabled: false,
            },
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created(){
            this.findData();
            this.gainUpdateRow();
        },
        methods:{
            //获取用户信息
            findData(){
                axios({
                    method: "GET",
                    url: "/user/gainData",
                }).then((res)=>{
                    console.log(res.data);
                    if(res.data==''){
                        this.$message("您尚未登录")
                    }else{
                        this.admin.username=res.data.username;
                        this.admin.imgAvatar=res.data.avatar;
                    }
                });
            },
            //获取修改数据
            gainUpdateRow(){
                axios({
                    method: "GET",
                    url: "/blog/gainBlog",
                }).then((res)=>{
                    console.log(res.data);
                    this.rowBlog.id=res.data.id;
                    this.rowBlog.title=res.data.title;
                    this.rowBlog.content=res.data.content;
                    this.rowBlog.typeId=res.data.type.id;
                    var str="";
                    this.rowBlog.tagIds=str;
                    this.rowBlog.firstPicture=res.data.firstPicture;
                    this.rowBlog.recommend=res.data.recommend;
                    this.rowBlog.shareStatement=res.data.shareStatement;
                    this.rowBlog.appreciation=res.data.appreciation;
                    this.rowBlog.commentabled=res.data.commentabled;
                });
            },
            //跳转到后台管理页面
            getBack(){
                location.href = "manage.html";
            }
        }
    });
</script>
</html>